package com.jiuyin.dianjing.thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Administrator
 */
public class ThreadPoolManager {
    private static final int KEEP_ALIVE_TIME = 1;
    private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS;
    private static int NUM_OF_CORES = Runtime.getRuntime().availableProcessors();
    private ExecutorService mExecutorService;

    private ThreadPoolManager() {
        BlockingDeque<Runnable> mBlockingDeque = new LinkedBlockingDeque<>();
        mExecutorService = new ThreadPoolExecutor(NUM_OF_CORES, NUM_OF_CORES, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, mBlockingDeque);
    }

    public static ThreadPoolManager getInstance() {
        return Holder.INSTANCE;
    }

    public ExecutorService getExecutorService() {
        return mExecutorService;
    }

    private static final class Holder {
        private static final ThreadPoolManager INSTANCE = new ThreadPoolManager();
    }
}
